package com.scnlf.scnlf.gateway.config;

import com.scnlf.scnlf.common.api.dto.CustomRouteParam;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;

import javax.annotation.PostConstruct;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Slf4j
@Data
@Configuration
@ConfigurationProperties(prefix = "customer.route")
public class CustomRouteConfig {

    private Boolean enable;

    private List<CustomRouteParam> params;

    @PostConstruct
    public void init(){
        log.info("init CustomRouteConfig");
    }

    /**
     * 这里模拟流程，效率问题忽略处理了
     * @param serviceName
     * @return
     */
    public List<CustomRouteParam> getRouteConfig(String serviceName){
        return params.stream()
                .filter(param -> Objects.equals(serviceName, param.getServiceId()))
                .collect(Collectors.toList());
    }

}
